package com.ymxk.timestar.activity.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.ymxk.timestar.activity.R;
import com.ymxk.timestar.view.drag.DragDataEntity;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * 添加记忆选择图片、MemoryAdd
 */
public class StarAtlasAdapter extends CommonAdapter<DragDataEntity> {

    public StarAtlasAdapter(Context context) {
        super(context, R.layout.item_star_atlas_list, new ArrayList<>());
    }

    @Override
    protected void convert(ViewHolder viewHolder, DragDataEntity item, final int position) {

        //View convertView = viewHolder.getConvertView();
        //convertView.setVisibility(item.isCheck ? View.VISIBLE : View.INVISIBLE);
        ImageView ivStarIcon = viewHolder.getView(R.id.ivStarIcon);
        ivStarIcon.setTag(position);
        RecyclerView rvLevelList = viewHolder.getView(R.id.rvLevelList);
        RecyclerView rvLevelListRight = viewHolder.getView(R.id.rvLevelListRight);

        TextView tvNameLeft = viewHolder.getView(R.id.tvNameLeft);
        TextView tvNameRight = viewHolder.getView(R.id.tvNameRight);

        onShowName(tvNameLeft, tvNameRight, true, String.valueOf(position).concat("--->"));
        Glide.with(mContext)
                .load(item.getThumbnailUrl())
                .into(ivStarIcon);

//        Glide.with(mContext)
//                .load("https://oss.res.gomezsz.com/oss-res/time-res/uat/8f20f84104d14a2999c03abb9a3f7792.jpg")
//                .into(ivStarIcon);

//        Glide.with(mContext)
//                .load("https://test-cos.gomezhe.com/oss-res/time-res/2ef561924c484668b4d46654881da087.jpg")
//                .into(ivStarIcon);

//        if (item.data instanceof StarAtlasRes) {
//            StarAtlasRes data = (StarAtlasRes) item.data;
//            Glide.with(mContext).load(data.getCoordinate_galaxy_image_url()).into(ivStarIcon);
//            if (position == 3 || position == 4 || position == 5) {
//                onShowName(tvNameLeft, tvNameRight, true, data.getName());
//                if (rvLevelList.getAdapter() == null) {
//                    onInitRecyclerView(rvLevelList, item.data);
//                } else {
//                    StarAtlasLevelAdapter adapter = (StarAtlasLevelAdapter) rvLevelList.getAdapter();
//                    adapter.getDatas().clear();
//                    List<StarAtlasRes.LevelListBean> listData = createListData(data.getLevel_list());
//                    adapter.getDatas().addAll(listData);
//                    adapter.notifyDataSetChanged();
//                }
//                rvLevelList.setVisibility(View.VISIBLE);
//                rvLevelListRight.setVisibility(View.GONE);
//            } else {
//                onShowName(tvNameLeft, tvNameRight, false, data.getName());
//                if (rvLevelListRight.getAdapter() == null) {
//                    onInitRecyclerView(rvLevelListRight, item.data);
//                } else {
//                    StarAtlasLevelAdapter adapter = (StarAtlasLevelAdapter) rvLevelListRight.getAdapter();
//                    adapter.getDatas().clear();
//                    List<StarAtlasRes.LevelListBean> listData = createListData(data.getLevel_list());
//                    adapter.getDatas().addAll(listData);
//                    adapter.notifyDataSetChanged();
//                }
//                rvLevelList.setVisibility(View.GONE);
//                rvLevelListRight.setVisibility(View.VISIBLE);
//            }
//        }
    }

    private void onShowName(TextView tvNameLeft,
                            TextView tvNameRight,
                            boolean isLeft,
                            String name) {
        if (isLeft) {
            tvNameLeft.setVisibility(View.VISIBLE);
            tvNameLeft.setText(name);
            tvNameRight.setVisibility(View.GONE);

        } else {
            tvNameRight.setVisibility(View.VISIBLE);
            tvNameRight.setText(name);
            tvNameLeft.setVisibility(View.GONE);
        }
    }

//    private void onInitRecyclerView(RecyclerView rv, Object object) {
//        rv.setLayoutManager(new LinearLayoutManager(mContext));
//        rv.setHasFixedSize(true);
//        rv.setNestedScrollingEnabled(false);
//        if (object instanceof StarAtlasRes) {
//            StarAtlasRes data = (StarAtlasRes) object;
//            List<StarAtlasRes.LevelListBean> listData = createListData(data.getLevel_list());
//            StarAtlasLevelAdapter mAdapter = new StarAtlasLevelAdapter(rv.getContext(), listData);
//            rv.setAdapter(mAdapter);
//        }
//    }

    //private List<StarAtlasRes.LevelListBean> list = new ArrayList<>();

//    private List<StarAtlasRes.LevelListBean> createListData(List<StarAtlasRes.LevelListBean> data) {
//        List<StarAtlasRes.LevelListBean> list = new ArrayList<>();
//        list.clear();
//        StarAtlasRes.LevelListBean bean = new StarAtlasRes.LevelListBean();
//        bean.levelTitle = "级别";
//        bean.planetCountTitle = "总量";
//        bean.monthlySales = "本月现售";
//        list.add(bean);
//        if (data != null) {
//            list.addAll(data);
//        }
//        return list;
//    }


}